package com.flea.hclv.controller;

import com.alibaba.fastjson.JSON;
import com.flea.hclv.model.entity.HCarCalendar;
import com.flea.hclv.service.HCarCalendarService;
import com.flea.hclv.util.ServerResponse;
import com.flea.system.platform.session.FleaOrgUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @program: project
 * @description: 车队日程表
 * @author: shiliqiang
 * @create: 2018-11-02 22:12
 * @version: 1.0
 */
@Controller
@RequestMapping("/flea/hclv/car/calendar/")
public class HCarCalendarController {

    @Autowired
    private HCarCalendarService hCarCalendarService;

    @RequestMapping("batch_insert")
    @ResponseBody
    public ServerResponse<String> batchInsert(HttpServletRequest request, String model){
        String userId = FleaOrgUtils.getCurUserUuid(request);

        return hCarCalendarService.insertList(model,userId);
    }
    @RequestMapping("batch_update")
    @ResponseBody
    public ServerResponse<String> batchUpdate(HttpServletRequest request,String model){
        String userId = FleaOrgUtils.getCurUserUuid(request);
        List<HCarCalendar> hCarCalendars = JSON.parseArray(model,HCarCalendar.class);
        return hCarCalendarService.updateList(hCarCalendars,userId);
    }
    /**
     * 默认显示当前月份
     * @param carId  车辆ID
     * @return list
     */
    @RequestMapping("select_current_month")
    @ResponseBody
    public ServerResponse<List<HCarCalendar>> selectCurrentMonth(String carId){
        return hCarCalendarService.selectCurrentMonth(carId);
    }
    /**
     * 按月份查询
     * @param carId  车辆ID
     * @return list
     */
    @RequestMapping("select_by_month")
    @ResponseBody
    public ServerResponse<List<HCarCalendar>> selectByMonth(String carId,String time){
        return hCarCalendarService.selectByMonth(carId,time);
    }

}
